#ifndef _R_Object_h
#define _R_Object_h

#include <stdlib.h>
#include <stdio.h>

#include <Ape/CompileTimeConfig.h>

/**
* Class meta info macro
*/
#define TYPE_NAME(sName) \
	public: \
	static const char* getTypeName() { \
		return sName;\
	};\
	virtual const char* getVTypeName() const { \
		return  sName; \
	} \
	virtual const size_t __SizeOf() const { \
		return sizeof(*this); \
	} \
	private:

#define ABSTRACT(sName) \
	public: \
	static const char* getTypeName() { \
		return sName;\
	};\
	virtual const char* getVTypeName() const = 0;\
	private:


#define DUMP_NON_V_TYPE printf("\t*** %s ***" _R_NEWLINE, getTypeName());

#define DUMP_PROPERTY(sPropName, oProperty) \
	Ape::IO::StdOut << L"\t\t" << sPropName << L":\t" << oProperty << Ape::IO::NewLine;

#define null NULL

/**
* Delete for scalar types
*/
#define del(var) \
	{ \
		delete var; \
		var = NULL; \
	} \
	 
/**
* Delete for arrays
*/
#define del_a(var) \
	{ \
		delete[] var; \
		var = NULL; \
	} \

#define _R_NEWLINE "\n"
#define _R_W_NEWLINE L"\n"

/**
* Base of bases
*/
namespace Ape {
	class String;
	namespace MT {
		class Mutex;
	}
	
	namespace EventModel {
		class Callback;
	}
	
	struct EMPTY;
	struct CallbackJoint;
	
	class Object {
		TYPE_NAME ("Ape::Object")
	private:
		// for ShPtr<P_t>
		mutable size_t m_RefCount;
		
		// for Delegates
		mutable CallbackJoint* m_Callbacks;
		void initCallbacksQueue();
		void destroyCallbacksQueue();
		
		// for lockables
		mutable MT::Mutex* m_Mutex;
	protected:
		/**
			ctor
		*/
		Object();
		/**
			copy ctor
		*/
		Object (const Object& other);
		
		void InitObjectMutex();
		void DestroyObjectMutex();
		MT::Mutex& GetObjectMutex() const;
	public:
		virtual ~Object();
		
		/**
			@param verbose do a verbose dump
		*/
		virtual void _Dump (bool verbose = false) const;
		
		virtual const String ToString() const;
		
		size_t __AddRef() const;
		size_t __RemRef() const;
		size_t __GetRef() const;
		
		void __AppendCallback (EventModel::Callback* callback) const;
	};
	
	
}

#endif // _R_Object_h
